/**
 * Copyright (C) 2010 Cloudfarming <info@cloudfarming.nl>
 *
 * Licensed under the Eclipse Public License - v 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nl.cloudfarming.client.sensor;

import com.vividsolutions.jts.geom.Point;
import nl.cloudfarming.client.geoviewer.LayerObject;
import nl.cloudfarming.client.geoviewer.LayerObjectAction;
import nl.cloudfarming.client.model.SensorData;
import nl.cloudfarming.client.util.GeometryUtil;
import org.geotools.geometry.jts.JTSFactoryFinder;

/**
 *
 * @author Timon Veenstra
 */
public class SensorDataLayerObject implements LayerObject<Point,SensorData> {

    private final Point geometry;
    private final SensorData sensorData;
    private final KeyAttribute keyAttribute;
    
    public SensorDataLayerObject(SensorData SensorData, KeyAttribute keyAttribute) {
        this.keyAttribute = keyAttribute;
        this.geometry = GeometryUtil.getPoint(JTSFactoryFinder.getGeometryFactory(null), SensorData.getLongitude(), SensorData.getLatitude()); 
        this.sensorData = SensorData;
    }

    @Override
    public Point getGeometry() {
        return this.geometry;
    }

    @Override
    public String getKey() {
        return Long.toString(this.sensorData.getId());
    }

    @Override
    public String getTooltipText() {
        return Long.toString(this.sensorData.getId());
    }

    @Override
    public Double getKeyAttributeValue() {
        if (KeyAttribute.Vi1.equals(this.keyAttribute)) {
            return this.sensorData.getCalculatedIndex1();
        } else {
            return this.sensorData.getCalculatedIndex2();
        }
    }

    @Override
    public long getId() {
        return this.sensorData.getId();
    }

    @Override
    public SensorData getObject() {
        return this.sensorData;
    }

    @Override
    public LayerObjectAction[] getActions() {
        return null;
    }

    @Override
    public void save() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public enum KeyAttribute {

        Vi1, Vi2;
    }
}
